CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

AUTO_SOURCES(unit_SOURCES "*.cpp" "RECURSE" ${CMAKE_CURRENT_SOURCE_DIR})

INCLUDE_DIRECTORIES(${gmock_INCLUDE_DIR} ${gtest_INCLUDE_DIR} ${libhdfs3_ROOT_SOURCES_DIR})

IF(NEED_BOOST)
    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ENDIF(NEED_BOOST)

INCLUDE_DIRECTORIES(${libhdfs3_ROOT_SOURCES_DIR})
INCLUDE_DIRECTORIES(${libhdfs3_COMMON_SOURCES_DIR})
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${libhdfs3_PLATFORM_HEADER_DIR})
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${KERBEROS_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${GSASL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/mock)

ADD_DEFINITIONS(-DMOCK)

PROTOBUF_GENERATE_CPP(libhdfs3_PROTO_SOURCES libhdfs3_PROTO_HEADERS ${libhdfs3_PROTO_FILES})

SET(libhdfs3_SOURCES ${libhdfs3_SOURCES} ${libhdfs3_MOCK_SOURCES})

ADD_EXECUTABLE(unit EXCLUDE_FROM_ALL
    ${gtest_SOURCES}
    ${gmock_SOURCES}
    ${libhdfs3_SOURCES} 
    ${libhdfs3_PROTO_SOURCES} 
    ${libhdfs3_PROTO_HEADERS}
    ${unit_SOURCES}
)

TARGET_LINK_LIBRARIES(unit pthread)

IF(NEED_BOOST)
    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${Boost_LIBRARY_DIRS}")
    TARGET_LINK_LIBRARIES(unit boost_thread)
    TARGET_LINK_LIBRARIES(unit boost_chrono)
    TARGET_LINK_LIBRARIES(unit boost_system)
    TARGET_LINK_LIBRARIES(unit boost_atomic)
    TARGET_LINK_LIBRARIES(unit boost_iostreams)
ENDIF(NEED_BOOST)

IF(NEED_GCCEH)
	TARGET_LINK_LIBRARIES(unit gcc_eh)
ENDIF(NEED_GCCEH)

IF(OS_LINUX)
    TARGET_LINK_LIBRARIES(unit ${LIBUUID_LIBRARIES})
    INCLUDE_DIRECTORIES(${LIBUUID_INCLUDE_DIRS})
ENDIF(OS_LINUX)

TARGET_LINK_LIBRARIES(unit ${PROTOBUF_LIBRARIES})
TARGET_LINK_LIBRARIES(unit ${LIBXML2_LIBRARIES})
TARGET_LINK_LIBRARIES(unit ${KERBEROS_LIBRARIES})
TARGET_LINK_LIBRARIES(unit ${GSASL_LIBRARIES})

SET(unit_SOURCES ${unit_SOURCES} PARENT_SCOPE)

